package org.eece262.taskshareserver;

import com.google.appengine.api.datastore.Key;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import org.edu.eece262.taskshare.Messages;

@PersistenceCapable
public class Task {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;
    
    @Persistent
    private int local_id;
    
    @Persistent
	private String name;
    
    @Persistent
    private String user;
	
    @Persistent
    private String notes;
    
    @Persistent
    private String location;
	
    @Persistent
    private int global_parent;
	
    @Persistent
    private int due_date;
	
    @Persistent
    private int due_time;
	
    @Persistent
    private int percent_complete;
	
    @Persistent
    private int done;
	
    @Persistent
    private int priority;
    
    public Task(Messages.Task task, String user) {
    	update(task);
    	this.user = user;
    }
    
    public Key getKey() {
        return key;
    }

	public int getLocal_id() {
		return local_id;
	}

	public void setLocal_id(int localId) {
		local_id = localId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public String getUser() {
		return user;
	}
	
	public void setUser(String user) {
		this.user = user;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public String getLocation() {
		return location;
	}

	public void setLocation(String location) {
		this.location = location;
	}

	public int getGlobal_parent() {
		return global_parent;
	}

	public void setGlobal_parent(int globalParent) {
		global_parent = globalParent;
	}

	public int getDue_date() {
		return due_date;
	}

	public void setDue_date(int dueDate) {
		due_date = dueDate;
	}

	public int getDue_time() {
		return due_time;
	}

	public void setDue_time(int dueTime) {
		due_time = dueTime;
	}

	public int getPercent_complete() {
		return percent_complete;
	}

	public void setPercent_complete(int percentComplete) {
		percent_complete = percentComplete;
	}

	public int getDone() {
		return done;
	}

	public void setDone(int done) {
		this.done = done;
	}

	public int getPriority() {
		return priority;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}
	
	public Messages.Task getMessagesTask() {
		Messages.Task rtnValue = new Messages.Task()
			.setGlobal_id(key.getId())
			.setLocal_id(local_id)
			.setName(name)
			.setNotes(notes)
			.setLocation(location)
			.setGlobal_parent(global_parent)
			.setDue_date(due_date)
			.setDue_time(due_time)
			.setPercent_complete(percent_complete)
			.setDone(done)
			.setPriority(priority);
		return rtnValue;
	}

	public void update(Messages.Task task) {
		local_id = task.getLocal_id();
    	name = task.getName();
    	notes = task.getNotes();
    	location = task.getLocation();
    	global_parent = task.getGlobal_parent();
    	due_date = task.getDue_date();
    	due_time = task.getDue_time();
    	percent_complete = task.getPercent_complete();
    	done = task.getDone();
    	priority = task.getPriority();
	}
}
